
#include "Logger.h"

using namespace devem;

void Logger::logMessage(LogLevel::Level level, const char* file, int line, const char* format, ...) {
    char header[256];
    snprintf(header, sizeof(header), "[%s][%d][%s][%s:%d]", FormatTime(), pid_, LogLevel::toString(level).c_str(), file,
             line);

    char message[1024];
    va_list args;
    va_start(args, format);
    vsnprintf(message, sizeof(message), format, args);
    va_end(args);

    std::cout << header << message << std::endl;
}

const char* Logger::FormatTime() {
    time_t t = time(NULL);
    struct tm* ltm = localtime(&t);
    snprintf(ret, sizeof(ret), "%d-%d-%d %d:%d:%d", ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday, ltm->tm_hour,
             ltm->tm_min, ltm->tm_sec);
    return ret;
}

Logger devem::logger;